/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/**
 * 新零售大屏管理
 *  */
import { getScreenLoginUser, generatePsw } from "@/services/api";
import { isLegalData } from "@/utils/utils";
import { message } from "antd";

export default {
  namespace: "bigScreen",

  state: {},

  effects: {
    // 获取登录用户列表、分享链接及密码
    *getScreenLoginUser({ payload, __dva_resolve, __dva_reject }, { call }) {
      const response = yield call(getScreenLoginUser, payload);

      if (!response) return;
      const { code, data = {}, msg } = response;
      const { link_data = {}, login_data = {} } = data;
      const { list = [] } = login_data;

      if (code == 0) {
        __dva_resolve({
          list: isLegalData(list),
          ...link_data,
        });
      } else {
        message.error(msg);
        __dva_reject();
      }
    },
    // 重置用户密码
    *generatePsw({ payload, __dva_resolve, __dva_reject }, { call }) {
      const response = yield call(generatePsw, payload);

      if (!response) return;
      const { code, data = {}, msg } = response;

      if (code == 0) {
        __dva_resolve(isLegalData(data, {}));
      } else {
        message.error(msg);
        __dva_reject();
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
